package hot;

import java.util.concurrent.ThreadPoolExecutor;

public class Num221 {
    public int maximalSquare(char[][] matrix) {
        int n = matrix.length;
        int m = matrix[0].length;
        int[][] dp = new int[n + 1][m + 1];
        int max = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(matrix[i][j] == '1') {
                    dp[i + 1][j + 1] = Math.min(Math.min(dp[i][j + 1],dp[i + 1][j]),dp[i][j]) + 1;
                    max = Math.max(max,dp[i + 1][j + 1]);
                }
            }
        }
        return max * max;
    }
}
